var week = {
    0: "星期日",
    1: "星期一",
    2: "星期二",
    3: "星期三",
    4: "星期四",
    5: "星期五",
    6: "星期六"
}

Date.prototype.weekDayCN = function () {

    return week[this.getDay()];
}
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds(),             //毫秒
        "E": this.weekDayCN()
    };
    fmt = fmt || "yyyy-MM-dd hh:mm:ss";
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

Date.prototype.calculateInterval = function (type, fmt) {//0倒计时 1开始时间

    fmt = fmt || "hh:mm:ss";

    let interval;
    if (type == 0) {

        interval = (this.getTime() - new Date().getTime())
    } else {

        interval = (new Date().getTime() - this.getTime())
    }
    interval = interval > 0 ? (this.getTime() - new Date().getTime()) : 0

    return interval;
}


var intervalfmt = {
    interval: 1000 * 60 * 60 * 12,
    fmt: 'd',
    child: {
        interval: 1000 * 60 * 60,
        fmt: 'h',
        child: {
            interval: 1000 * 60,
            fmt: "m",
            child: {
                interval: 1000,
                fmt: 's'

            }
        }
    }
}

Date.prototype.parsefmt = function (val, fmt) {

    fmt = fmt || "yyyy-MM-dd hh:mm:ss";
    var d = {};
    for (var i in fmt) {
        d[fmt[i]] = (d[fmt[i]] || "") + "" + val[i];
    }
    var date = new Date();
    date.setDate(d.d || date.getDate());
    date.setMonth((parseInt(d.M) - 1) || date.getMonth());
    date.setFullYear(d.y || date.getYear());
    date.setHours(d.h || date.getHours());
    date.setMinutes(d.m || date.getMinutes());
    date.setSeconds(d.s || date.getSeconds());
    return date;
}